package website;

import java.util.Vector;

import accesory.Email;

import call4paper.*;
import exception.DoesNotUploadPaperJobException;
import exception.UserIsRevisorCFPException;

public class User {
	
	private String username, password;
	private Email email = new Email();
	private String lastName, firstName;
	private Vector<InterestArea> experience = new Vector<InterestArea>();
	private Vector<PaperJob> papers = new Vector<PaperJob>();
	private Vector<PaperJob> toBeRevised = new Vector<PaperJob>();
	
	public User(String username, String password, String firstName, String lastName, Vector<InterestArea> exp) {
		this.username  = username;
		this.password = password;
		this.firstName = firstName;
		this.lastName = lastName;
		this.experience.addAll(exp);
	}
	
	
	
	//METHODS
	public void readMessage(){
		this.email.readMessage();
	}
	
	public void getMessage(String text){
		this.email.sendMessage(text);
	}

	public CFP createCFP(String cfpName, Vector<InterestArea> intAreas, Vector<User> revisors){
		return new CFP(this, cfpName, intAreas, revisors);
	}
	
	public PaperJob createPaperJob(String title, String body, Vector<InterestArea> list) {
		PaperJob paper =  new PaperJob(this, title, body, list);
		this.papers.add(paper);
		return paper;
		
	}
	

	public void uploadPaperJob(PaperJob paper, CFP aCFP) throws UserIsRevisorCFPException, Exception {
		if(!aCFP.isRevisor(this))
			aCFP.uploadPaperJob(paper);
		else
			throw new UserIsRevisorCFPException();
	}
	
	/**
	 * El usuario evalua un paper job con una calificacion que el mismo le asigna,
	 * dejando un comentario sobre el trabajo.
	 * Una vez revisado, lo remueve de su lista de a revisar.
	 * @param paper
	 * @param quali
	 */
	public void evaluateJob(PaperJob paper, Qualification quali, String comment) {
		paper.qualify(this, quali, comment);
	}
	
	/**
	 * Retorna los paper de un CFP si es autor o, en caso de ser revisor,
	 * solo los paper asociado del el o todos los papers cuando el estado del cfp esta terminado. 
	 * @throws NotIsAuthorOrRevisorACFPException
	 */
	public Vector<PaperJob> checkAssignation(CFP aCFP){
		if(aCFP.getAuthor().equals(this))// si el CFP es del author
			return aCFP.getPaperJobs();
		else if(aCFP.getRevisors().contains(this)){//en caso que sea de un revisor
			return aCFP.checkAssignationCFP(this);//el retorno dependera el estado del cfp
		}
		else{//si no es revisor o autor de un cfp, retorno vacio.
			return null;
		}
			
	}
	

	public String getUsername() {
		return this.username;
	}



	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public Vector<InterestArea> getExperience() {
		return experience;
	}

	public void setExperience(Vector<InterestArea> experience) {
		this.experience = experience;
	}

	public Vector<PaperJob> getPapers() {
		return papers;
	}


	public void setPaper(PaperJob paper) {
		this.papers.add(paper);
	}

	public void setToBeRevized(Vector<PaperJob> toBeRevized) {
		this.toBeRevised = toBeRevized;
	}

	public Vector<PaperJob> getToBeRevized() {
		return toBeRevised;
	}






	
}
